package com.fyb.java.ai.langchain4j.config;

import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.model.embedding.EmbeddingModel;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.pinecone.PineconeEmbeddingStore;
import dev.langchain4j.store.embedding.pinecone.PineconeServerlessIndexConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置向量存储对象
 */
@Configuration
public class EmeddingStoreConfig {

    @Autowired
    private EmbeddingModel embeddingModel;

    @Bean
    public EmbeddingStore<TextSegment> emeddingStore(){
        //创建向量存储

        EmbeddingStore<TextSegment> embeddingStore = PineconeEmbeddingStore.builder()
                .apiKey("pcsk_5YZxXs_FNrxk6wMTYkoturojYf2kyX7ouYbWLDXcb5owjKohAd8oGDr8kS8rWCiwT3pdgr")
                .index("xiaozhi-index")//如果指定的索引不存在,将创建一个新的索引
                .nameSpace("xiaozhi-namespace")//如果指定的命名空间不存在,将创建一个新的命名空间
                .createIndex(PineconeServerlessIndexConfig.builder()
                        .cloud("AWS")//指定索引部署在AWS云服务上
                        .region("us-east-1")//指定索引所在的AWS区域为us-east-1
                        .dimension(embeddingModel.dimension())//指定索引的向量维度,该维度与emebddingModel生成的向量维度相同
                        .build())
                .build();
        return embeddingStore;
    }
}
